package cn.tedu.spring.ti3;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
//@Value  给属性注入值
//加注解

@Configuration
@PropertySource(value = {"classpath:ti3.properties"}, encoding = "Unicode")
//用@Value注解读取application.properties文件时，编码默认是ISO-8859-1，所以直接配置中文一定会乱码，而我们需要将该文件转变成UTF-8的编码格式
@Component
public class Demo {
    @Value("${name}")
    private String name;
    @Value("${age}")
    private int age;
    @Value("#{@list1}")//注解加xml完成值的注入  #{@+xml中配置的id属性}
    private List<String> list;
    @Value("#{@set1}")
    private Set<String> set;
    @Value("#{@map1}")
    private Map<String,Object> map;
    @Value("#{@prope1}")
    private Properties properties;

    @Override
    public String toString() {
        return "Demo{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", list=" + list +
                ", set=" + set +
                ", map=" + map +
                ", properties=" + properties +
                '}';
    }
}
